package com.face.zf.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Author: (ﾉ ◠ ‿ ◠)ﾉ wangYu
 * @CreateTime: 2025-07-23
 * @IDE:IDEA
 * @ContactMe WECHAT-> wy10012311   QQ-> 1569350611
 * @Description: 配置加载工具类
 */

public class PropertiesPool {

    private static final Logger logger = LoggerFactory.getLogger(PropertiesPool.class);

    private static Properties application;
    private static final String applicationPath = "application.properties";


    static {
        loadProperties();
    }

    private static synchronized void loadProperties() {
        if (application == null) {
            InputStream ins = null;
            try {
                ins = PropertiesPool.class.getClassLoader().getResourceAsStream(applicationPath);
                application = new Properties();
                application.load(ins);
                logger.info("加载" + applicationPath + "完成...");
            } catch (Exception e) {
                logger.error("加载" + applicationPath + "出错!", e);
            } finally {
                if (ins != null) {
                    try {
                        ins.close();
                    } catch (IOException e) {
                        logger.error("关闭" + applicationPath + "文件流出错!", e);
                    }
                }

            }
        }
    }

    public static Properties obtainProperties() {
        if (application == null) {
            loadProperties();
        }
        return application;
    }
}
